import TIM from 'tim-wx-sdk-ws'
import { formatTime } from '../../../../utils/date'
import { getDataSet, getEventParam } from '../../../../utils/utils'
// pages/conversation/compoents/message/message.js
Component({
	/**
	 * 组件的属性列表
	 */
	properties: {
		message: Object,
	},
	observers: {
		message: function (message) {
			console.log(message)
			message.time = formatTime(message.time)
			this.setData({
				_message: message,
			})
		},
	},
	/**
	 * 组件的初始数据
	 */
	data: {
		_message: null,
		TIM: TIM,
		flowEnum: {
			IN: 'in',
			OUT: 'out',
		},
	},

	/**
	 * 组件的方法列表
	 */
	methods: {
		handleSend(event) {
			const service = getEventParam(event, 'service')
			this.triggerEvent('send', { service })
		},
		handleSelect(event) {
			const service = getEventParam(event, 'service')
			this.triggerEvent('select', { service })
		},
		async handlePreview(event) {
			console.log('111')
			const url = getDataSet(event, 'image')
			await wx.previewImage({
				urls: [url],
				current: url,
			})
		},
	},
})
